package com.hippy.struts.DBC3P0Pool;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DbPool {
	private static String URL = DbProperty.getInstance().getProperty("URL");
	private static String DRIVERCLASS = DbProperty.getInstance().getProperty(
			"DRIVERCLASS");
	private static String USERNAME = DbProperty.getInstance().getProperty(
			"USERNAME");
	private static String PASSWORD = DbProperty.getInstance().getProperty(
			"PASSWORD");

	public Connection getConnection() {
		Connection con = null;
		try {
			Class.forName(DRIVERCLASS);
			con = DriverManager.getConnection(URL, USERNAME, PASSWORD);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return con;
	}

	public void closeAll(ResultSet rs, Statement statement, Connection con) {
		try {
			if (!rs.isClosed() && rs == null) {
				rs.close();
			}
			if (statement == null) {
				statement.close();
			}
			if (con == null) {
				con.close();
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}
